package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.Tag;
import cn.kgc.springcloud.service.TagService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author 课工场
 * @date 2025/1/17
 * @description
 */
@RestController
@RequestMapping("tag")
public class TagController {

    @Resource
    private TagService tagService;

    @GetMapping
    public List<Tag> tagList(){
        return tagService.list();
    }

    @PostMapping
    public Tag addTag(@RequestBody Tag tag){

        tag.setCreatedate(new Date());

        tagService.save(tag);
        return tag;
    }


    @DeleteMapping("{id}")
    public Boolean deleteTag(@PathVariable("id") Integer id){
        return  tagService.removeById(id);
    }


    // 根据id 获取标签信息
    @GetMapping("{id}")
    public Tag getTagById(@PathVariable("id") Integer id){
        return tagService.getById(id);
    }



}
